//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    currentTab: 0,
    stars: [0, 1, 2, 3, 4],
    normalSrc: '../../images/normal.png',
    selectedSrc: '../../images/selected.png',
   spList:[],
    rqkey: [],//评分
    kbkey:[],
    sellerInfo: '宁波乐玛摄影工作室',
    num1: '156',
    num2: '4',
    num3: '3',
    num4: '4',
    src: '../../images/banner.jpg',
    infoTxtarea: '“在这里非常感谢我的摄影师王聪老师和化妆师星子老师很专业，拍摄当天的照片没有修图我就很满意 妆容也是我喜欢的简约”',
   newkb:[],
      
    currentTab2:0,
    top:[
      { name: "全部" },
      { name:"婚纱摄影"},
      { name:"婚宴"},
      { name: "婚礼策划"},
      { name:"婚纱礼服"}

    ]
  },
    gogogo:function(){
      wx.navigateTo({
      url: '../search/index',
    })

    },
    getnewkb:function(){
     var that=this;
     var newkb=[];
     wx.request({
       url:'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=get_new_assess',
       method:'get',
       header:{
         'content-type':'application/json'
       },
       success(res){
         that.setData({
           newkb:res.data
         })
         console.log(that.data.newkb)
       }
     })

    },
   
  getrqlist: function () {
    var that = this;
    var rqinfoList = [];
    var rqkey = [];
    console.log(111)
    console.log(app.globalData.openid);
    wx.request({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=Ranking&status=1',
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log(res)
        rqinfoList = res.data;
        for (var i in rqinfoList) {
          rqkey[i] = rqinfoList[i].k_info.avg;
        }
        that.setData({
          rqinfoList: rqinfoList,
          rqkey: rqkey
        })
        console.log("rq")
        console.log(that.data.rqkey)
      }
    })
  },
  getkblist: function () {
    var that = this;
    var kbinfoList = [];
    var kbkey = [];
    console.log(111)
    console.log(app.globalData.openid);
    wx.request({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=Ranking&status=2',
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log(res)
        kbinfoList = res.data;
        for (var i in kbinfoList) {
          kbkey[i] = kbinfoList[i].k_info.avg;
        }
        that.setData({
          kbinfoList: kbinfoList,
          kbkey: kbkey
        })
        console.log("kb")
        console.log(that.data.kbinfoList)
      }
    })
  },

  tabswiper:function(e){
    var that=this;
    console.log(e)
    if(e.target.dataset.current===that.data.currentTab)
    return false;
    else 
    that.setData({currentTab:e.target.dataset.current})

  },
  navListTxtTap: function (e) {
    var that = this;
    var kbkey=[];
    if (e.target.dataset.current === that.data.currentTab2)
      return false;
    else
      that.setData({ currentTab2: e.target.dataset.current})

  console.log(e)
  var kbinfoList = [];
    var word = that.data.top[e.target.dataset.current].name;
   console.log(word)

    //触发点击事件时，跳转到指定位置
    wx.pageScrollTo({
     scrollTop: 200
   })
   
    wx.request({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=search&keyword=' + word,
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log(res)
        kbinfoList = res.data;
         for (var i in kbinfoList) {
          kbkey[i] = kbinfoList[i].k_info.avg;
      }
        that.setData({
          kbinfoList: kbinfoList,
         
        })
      
      }
    })

  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      
    })
  },

  onLoad: function () {
    app.getopenid();
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })
    that.getrqlist();
    that.getkblist();
   that.getnewkb();

  }
})

